import { isIntegerKey } from "@vue/shared";
import { ref } from "vue";
//随机生成id
export const getId = (length) => {
  let result = "";
  for (let i = 0; i < length; i++) {
    result += Math.floor(Math.random() * 10); // 生成一个0到9之间的随机数字
  }
  return result;
};

//封装函数将infoChecked.value转化成字符串存储
export const getInfo = (arr) => {
  const str = ref("");
  for (let i in arr) {
    if (i < arr.length - 1) {
      str.value = str.value + arr[i] + ",";
    } else {
      str.value = str.value + arr[i];
    }
  }
  return str.value;
};

//上传文件的字符串检测
//包含中英文、数字、-、。
//TODO:上传正则表达式的编写
export const testStr = (str) => {
  const reg = /[^，a-zA-Z,-/.0-9\u4e00-\u9fa5]/u;
  return reg.test(str);
};


//将数组中的数字字符转化成数字类型

export const changeArr = (arr) => {
  for (let i = 0; i < arr.length; i++) {
    if (arr[i].includes("-")) {
      continue;
    } else if (arr[i] == "0") {
      arr[i] = 0;
    } else if (Number.isInteger(arr[i])) {
      //明确判断是不是整型
      arr[i] = parseInt(arr[i]);
    } else if (Number.parseFloat(arr[i])) {
      //尝试转化成浮点型
      arr[i] = parseFloat(arr[i]);
    }
  }
  return arr;
};
